<template>
  <div class="index">
    <!-- 轮播图 -->
    <div class="index-carousel">
      <div class="index-carouselbackgroundred">
        <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
          <van-swipe-item>
            <img v-for="img in carousel" v-lazy="img" :key="img" />
          </van-swipe-item>
          <van-swipe-item>
            <img v-for="img in carousel" v-lazy="img" :key="img" />
          </van-swipe-item>
          <van-swipe-item>
            <img v-for="img in carousel" v-lazy="img" :key="img" />
          </van-swipe-item>
          <van-swipe-item>
            <img v-for="img in carousel" v-lazy="img" :key="img" />
          </van-swipe-item>
        </van-swipe>
      </div>
    </div>
    <!-- end -->

    <!-- 保障 -->
    <div class="safeguard">
      <span v-for="(item, index) in indexsafeguard" :key="index">
        <img v-for="img in safeguard" v-lazy="img" :key="img" />
        {{ item }}
      </span>
    </div>
    <!-- end -->

    <!-- 调查 -->
    <div class="surveya">
      <div class="surveyitema">
        <div class="surveybox">
          <div>有奖用户调查</div>
          <div>
            填写信息后并提交截图，联系微信小秘书<span>"CYYP2021"</span>免费获得潮袜一双
          </div>
          <div>立即参与</div>
          <img
            class="surveyimg"
            v-for="img in surveya"
            v-lazy="img"
            :key="img"
          />
        </div>
      </div>
    </div>
    <!-- end -->

    <!-- 分类 -->
    <div class="clas">
      <van-swipe @change="onChange">
        <van-swipe-item>
          <ul v-for="(item, index) in arrcls" :key="index">
            <li>
              <img :src="item.arrimg" alt="" />
              <span>{{ item.Text }}</span>
            </li>
          </ul>
        </van-swipe-item>
        <van-swipe-item>
          <ul v-for="(item, index) in arrcls2" :key="index">
            <li>
              <img :src="item.arrimg" alt="" />
              <span>{{ item.Text }}</span>
            </li>
          </ul>
        </van-swipe-item>

        <template #indicator>
          <div
            class="custom-indicator mincarousel1"
            :class="{ mincarousel2: current == 0 }"
          >
            <span><span></span></span>
          </div>
        </template>
      </van-swipe>
    </div>
    <!-- end -->

    <!-- 推荐 -->
    <div class="recommmend">
      <div class="swipeleft">
        <div class="swipelefttext">
          <span>T 恤 推 荐</span><br />
          <span>尽显活力四射</span>
        </div>
        <van-swipe class="my-swipe" :autoplay="2000" indicator-color="white">
          <van-swipe-item>
            <img v-for="img in recommmend" v-lazy="img" :key="img" />
          </van-swipe-item>
          <van-swipe-item>
            <img v-for="img in recommmend" v-lazy="img" :key="img" />
          </van-swipe-item>
          <van-swipe-item>
            <img v-for="img in recommmend" v-lazy="img" :key="img" />
          </van-swipe-item>
        </van-swipe>
      </div>
      <div class="recommmendright">
        <div class="recommmendrighttop">
          <div>春季特卖</div>
          <div class="cwei">C位爆款</div>
          <img
            src="../../../../static/images/home/Carouselmin01-home.png"
            alt=""
          />
          <img
            src="../../../../static/images/home/Carouselmin02-home.png"
            alt=""
          />
        </div>
        <div class="recommmendrighttop recommmendrightbo">
          <div>超值精选</div>
          <div class="cwei tunj">人气推荐</div>
          <img
            src="../../../../static/images/home/Carouselmin03-home.png"
            alt=""
          />
          <img
            src="../../../../static/images/home/Carouselmin04-home.png"
            alt=""
          />
        </div>
      </div>
    </div>
    <!-- end -->

    <!-- 人气榜单 -->
    <div class="popularity">
      <!-- 榜单列表头部 -->
      <h1>HOT人气榜单</h1>
      <div class="titleinput">
        <span>更多潮流尖货<span>点击查看+</span></span>
      </div>
      <!-- 榜单列表 -->
      <div v-for="(item, index) in popularityjson" :key="index">
        <popularity>
          <template #popularityleftimg>
            <img
              :src="item.imgleft + index + item.imgleftgoot"
              alt=""
              @click="detail"
            />
          </template>
          <template #popularitytitle>
            {{ item.title }}
          </template>
          <template #popularitytitledescribe>
            {{ item.describe }}
          </template>
          <template #popularitydescribe2>
            {{ item.describe2 }}
          </template>

          <template #popularityimgurl1>
            <img :src="item.imgurl1" alt="" @click="detail" />
          </template>
          <template #popularityimgurl2>
            <img :src="item.imgurl2" alt="" @click="detail" />
          </template>
          <template #popularityimgurl3>
            <img :src="item.imgurl3" alt="" @click="detail" />
          </template>

          <template #popularityclassify>
            {{ item.classify }}
          </template>
        </popularity>
      </div>
    </div>
    <!-- end -->
    <!-- 每日秒杀 -->
    <div class="dailySeckill">
      <div class="dailySeckill-head">
        <h1 class="dailySeckill-head-title">
          每日秒杀
          <van-tag round type="primary" color="#f15c45" class="van-primary"
            >15点抢</van-tag
          >
        </h1>
        <p class="dailySeckill-head-more" @click="torouteFn">
          查看更多<van-icon name="arrow" class="van-arrow" />
        </p>
      </div>
      <!-- 秒杀列表 -->
      <dailySeckillList ref="torouteFn"></dailySeckillList>
    </div>

    <!-- 精选小轮播图 -->
    <div>
      <carefully></carefully>
    </div>

    <!-- 商品详情 -->
    <div>
      <goodList :dataList="goodList"> </goodList>
    </div>

    <!-- 回到顶部 -->
    <div>
      <Backtotop> </Backtotop>
    </div>

    <div class="foot"></div>

    <div class="foot"></div>
  </div>
</template>

<script>
// 人气榜单
import popularity from "../../../components/home/popularity";
// 秒杀列表数据
import dailySeckillList from "../children/dailySeckillList";
// 精选小轮播图
import carefully from "../../../components/home/carefully";
// 商品详情
import goodList from "../../../components/goodList/goodList";
// 回到顶部
import Backtotop from "../../../components/home/Backtotop";

// 引入Lazyload 插件
import Vue from "vue";
import { Lazyload } from "vant";
Vue.use(Lazyload);
Vue.use(Lazyload, {
  lazyComponent: true,
});

export default {
  mounted() {
    window.addEventListener("scroll", this.scrollToTop);
    // 人气列表json数据
    this.$axios
      .get("../../../static/json/home/popularity.json")
      .then((res) => {
        this.popularityjson = res.data;
        // console.log(this.popularityjson);
      })
      .catch((err) => {
        console.log(err);
      });
      this.$axios.get('/goodList').then(res => {
          // console.log('goodList:', res.data.goodList);
          this.goodList = res.data.goodList;
      });
  },

  components: {
    popularity,
    dailySeckillList,
    carefully,
    goodList,
    Backtotop,
  },
  data() {
    return {
      scrollTop: 0,
      // // 懒加载真实图片入径
      carousel: [
        "../../../../static/images/home/Carousel1-home.png", //首页真实图片入径
      ],
      recommmend: [
        "../../../../static/images/home/Carouselmin1-home.png", //推荐轮播图真实图片入径
      ],
      safeguard: [
        "../../../../static/images/home/true.png", //保障真实图片入径
      ],
      surveya: [
        "../../../../static/images/home/investigation-home.png", //调查图真实图片入径
      ],

      popularityjson: null, //人气列表json数据
      current: 0,
      indexsafeguard: ["正品保障", "全国包邮", "72小时发货", "售后无忧"],
      arrcls: [
        {
          Text: "外套",
          arrimg: "../../../../static/images/home/classification1.png",
        },
        {
          Text: "西装",
          arrimg: "../../../../static/images/home/classification2.png",
        },
        {
          Text: "套装",
          arrimg: "../../../../static/images/home/classification3.png",
        },
        {
          Text: "裙子",
          arrimg: "../../../../static/images/home/classification4.png",
        },
        {
          Text: "卫衣",
          arrimg: "../../../../static/images/home/classification5.png",
        },
        {
          Text: "新人福利",
          arrimg: "../../../../static/images/home/classification6.png",
        },
        {
          Text: "短袖T恤",
          arrimg: "../../../../static/images/home/classification7.png",
        },
        {
          Text: "裤子",
          arrimg: "../../../../static/images/home/classification8.png",
        },
        {
          Text: "包包",
          arrimg: "../../../../static/images/home/classification9.png",
        },
        {
          Text: "男装",
          arrimg: "../../../../static/images/home/classification10.png",
        },
      ],
      arrcls2: [
        {
          Text: "男装",
          arrimg: "../../../../static/images/home/classification10.png",
        },
        {
          Text: "包包",
          arrimg: "../../../../static/images/home/classification9.png",
        },
        {
          Text: "裤子",
          arrimg: "../../../../static/images/home/classification8.png",
        },
        {
          Text: "短袖T恤",
          arrimg: "../../../../static/images/home/classification7.png",
        },
        {
          Text: "新人福利",
          arrimg: "../../../../static/images/home/classification6.png",
        },
        {
          Text: "卫衣",
          arrimg: "../../../../static/images/home/classification5.png",
        },
        {
          Text: "裙子",
          arrimg: "../../../../static/images/home/classification4.png",
        },
        {
          Text: "套装",
          arrimg: "../../../../static/images/home/classification3.png",
        },
        {
          Text: "西装",
          arrimg: "../../../../static/images/home/classification2.png",
        },
        {
          Text: "外套",
          arrimg: "../../../../static/images/home/classification1.png",
        },
      ],
      goodList: []
    };
  },
  methods: {
    onChange(index) {
      this.current = index;
    },
    // 子组件的编程式路由方法
    torouteFn() {
      this.$refs["torouteFn"].torouteFn();
    },
    // 路由跳转，点击商品跳转详情
    detail() {
      this.$router.push({ path: "/goodDetail" }).catch(err => {});
    },
  },
};
</script>

<style lang="less" scoped>
.foot {
  height: 100px;
}
.index {
  top: 18px;
  position: relative;
  background-color: #f6f6f6;
  .index-carousel {
    height: 238px;
    .index-carouselbackgroundred {
      padding-left: 19px;
      width: 100%;
      height: 160px;
      position: absolute;
      background-color: #c62724;
      border-bottom-right-radius: 20px;
      border-bottom-left-radius: 20px;
      top: 89px;
      z-index: 1;
    }
    img {
      width: 710px;
      height: 230px;
    }
  }
  // 推荐
  .recommmend {
    padding-left: 22px;
    overflow: hidden;
    .swipeleft {
      float: left;
      width: 345px;
      // height: 410px;
      position: relative;
      .swipelefttext {
        font-size: 10px;
        position: absolute;
        z-index: 1;
        text-align: center;
        top: 270px;
        left: 55px;
        color: white;
        span {
          &:nth-child(1) {
            font-size: 50px;
            background-color: #cf8e8c;
            padding: 3px 10px;
            margin-bottom: 2px;
          }
          &:nth-child(2) {
            font-size: 23px;
            font-weight: bold;
          }
        }
      }
      img {
        width: 100%;
        height: 100%;
      }
    }
    .recommmendright {
      .recommmendrighttop {
        height: 195px;
        padding-left: 30px;
        float: right;
        width: 340px;
        margin-right: 20px;
        background: #ffffff;
        border-radius: 15px;
        div {
          margin-top: 10px;
          margin-bottom: 5px;
          width: 800px;
          &:nth-child(1) {
            width: 131px;
            height: 29px;
            font-size: 30px;
            font-family: PingFang SC;
            font-weight: bold;
            color: #101010;
          }
        }
        .cwei {
          width: 120px;
          height: 23px;
          font-size: 24px;
          font-family: PingFang SC;
          font-weight: bold;
          color: #ff3226;
          line-height: 50px;
        }
        img {
          float: left;
          position: relative;
          &:nth-last-child(2) {
            margin-top: 10px;
            width: 113px;
            height: 104px;
          }
          &:nth-last-child(1) {
            position: absolute;
            right: 70px;
            top: 900px;
            width: 120px;
            height: 173px;
          }
        }
      }
      .recommmendrightbo {
        margin-top: 20px;
        img {
          float: left;
          position: relative;
          // &:nth-last-child(2){margin-top:10px; width: 113px;height: 104px;}
          &:nth-last-child(1) {
            position: absolute;
            right: 70px;
            top: 1115px;
            width: 120px;
            height: 173px;
          }
        }
        .tunj {
          color: #6e85ff;
        }
      }
    }
  }
  // 衣服分类
  .clas {
    margin-bottom: 120px;
    font-weight: bold;
    font-size: 27px;
    width: 710px;
    height: 245px;
    padding-left: 19px;
    ul {
      padding-left: 15px;
      li {
        width: 20%;
        float: left;
        text-align: center !important;
        padding-left: 8px !important;
        img {
          width: 116px;
          height: 116px;
        }
      }
    }
  }

  // 动态小轮播
  .mincarousel2 {
    span {
      span {
        float: left;
      }
    }
  }
  // 调查
  .surveya {
    .surveyitema {
      padding-left: 19px;
      position: relative;
      z-index: 10;
      margin-top: 23px;
      .surveybox {
        div {
          position: absolute;
          top: 10px;
          &:nth-child(1) {
            margin: 10px;
            top: 10px;
            width: 340px;
            height: 53px;
            font-size: 54px;
            font-family: HYb4gj;
            font-weight: 400;
            color: #ffffff;
            line-height: 50px;
          }
          &:nth-child(2) {
            margin-left: 10px;
            top: 85px;
            width: 450px;
            height: 47px;
            font-size: 22px;
            font-family: PingFang SC;
            font-weight: 500;
            color: #ffffff;
            line-height: 24px;
            span {
              text-align: center;
              color: #f4d567;
            }
          }
          &:nth-child(3) {
            border: 1px solid #f5cc6c;
            top: 150px;
            width: 120px;
            height: 40px;
            margin-left: 10px;
            background-color: #f5cd6c;
            border-radius: 20px;
            text-align: center;
            padding-top: 7px;
            line-height: 40px;
            font-size: 18px;
            font-family: PingFang SC;
            font-weight: 500;
            color: #603715;
            line-height: 24px;
          }
        }
      }
      .surveyimg {
        width: 710px;
        height: 205px;
      }
    }
  }

  // 保障
  .safeguard {
    height: 18px;
    margin-left: 25px;
    background-color: #f6f6f6;
    span {
      margin-bottom: 10px;
      font-size: 26px;
      width: 25%;
      float: left;
      line-height: 25px;
      img {
        margin-bottom: 10px;
        margin-right: 3px;
        float: left;
        margin-top: 0px;
        width: 30px;
        height: 30px;
      }
    }
  }
  // 人气榜单
  .popularity {
    margin-top: 20px;
    h1 {
      text-align: center;
      // width: 383px;
      height: 58px;
      font-size: 60px;
      font-family: PingFang SC;
      font-weight: bold;
      color: #060606;
      line-height: 50px;
    }
    .titleinput {
      line-height: 8px;
      margin: 0 auto;
      margin-top: 10px;
      padding-top: 2px;
      padding-left: 10px;
      width: 372px;
      height: 50px;
      border: 3px solid #ff8e7f;
      border-radius: 60px;
      span {
        &:nth-child(1) {
          margin-right: 3px;
          border-radius: 60px;
          padding-left: 7px;
          width: 158px;
          height: 40px;
          font-size: 30px;
          font-family: PingFang SC;
          font-weight: bold;
          color: #060606;
          line-height: 40px;
          span {
            float: right;
            &:nth-child(1) {
              background-color: #ff8e7f;
            }
          }
        }
      }
    }
  }
  // 每日秒杀
  .dailySeckill {
    width: 710px;
    margin: 0 auto;
    background-color: #fff;
    border-radius: 20px;
    .dailySeckill-head {
      width: 670px;
      margin: 0 auto;
      margin-top: 20px;
      display: flex;
      justify-content: space-between;
      .dailySeckill-head-title {
        font-size: 30px;
        color: #000;
        margin-top: 17px;
        font-weight: bold;
        .van-primary {
          margin-left: 7px;
          font-weight: 100;
          font-size: 18px;
        }
      }
      .dailySeckill-head-more {
        font-size: 24px;
        margin-top: 22px;
        color: #757575;
        .van-arrow {
          margin-top: 2px;
          vertical-align: -3px;
        }
      }
    }
  }
}

.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  line-height: 150px;
}
.index .surveya .surveyimg[data-v-4190901e] {
  margin-bottom: 20px;
}
.index .index-carousel .index-carouselbackgroundred[data-v-4190901e] {
  top: -18px;
}
.custom-indicator[data-v-4190901e] {
  margin-top: 15px;
}
// .surveybox{
//   width: 100%;
//   // height: 205px;
// }
</style>
